package com.pufa.demo.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.pufa.demo.service.IService;

@Controller
// @RequestMapping("/Demo")
public class DemoController {

	@Resource IService serviceImpl;
	/**
	 * 显示页
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/show")
	public String show(HttpServletRequest request, HttpServletResponse response) {
		request.setAttribute("haha", "haha");
		return "demo/demo";
	}
	
	/**
	 * 打印凭证号
	 * @param request
	 * @param response
	 */
	@RequestMapping("/print")
	public void savePingzh(HttpServletRequest request, HttpServletResponse response){
		List<String> list = serviceImpl.savePingzh(request.getParameter("pingzh"), request.getParameter("size"));
		JSONObject json = new JSONObject();
		json.put("list", list);
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = null;
        try {
            out = response.getWriter();
        } catch (IOException e) {
        }
        out.print(json);
        out.flush();
        out.close();
	}
	/**
	 * 验证凭证号
	 * @param request
	 * @param response
	 */
	@RequestMapping("/verify")
	public void verify(HttpServletRequest request, HttpServletResponse response) {
		boolean b = serviceImpl.verifyPingzh(request.getParameter("pingzh"));
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = null;
        try {
            out = response.getWriter();
        } catch (IOException e) {
        }
        out.print(b);
        out.flush();
        out.close();
	}
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
